<script setup>
const props = defineProps({
  modelValue: { type: Object, default: () => ({}) },
  type: { type: String, default: 'datetimerange' },
})
const emit = defineEmits(['update:modelValue'])
const date = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emit('update:modelValue', val)
  }
})

const config = {
  datetimerange: {
    valueFormat: 'YYYY-MM-DD HH:mm:ss',
    maxWidth: '380px'
  },
  daterange: {
    valueFormat: 'YYYY-MM-DD',
    maxWidth: '260px'
  },
}
const prop = config[props.type]
if (!prop) {
  console.error('VDate组件type只能是 daterange/datetimerange')
}

</script>

<template>
  <el-date-picker v-if="prop" v-model="date" :type="type" :value-format="prop.valueFormat" range-separator="至"
    start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1970-01-01T16:00:00Z'),new Date('1970-01-01T15:59:59Z')]"
    :style="{ maxWidth: prop.maxWidth }" v-bind="$attrs" />
</template>
